package edu.chinasoft.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.annotation.WebServlet;
import org.apache.log4j.Logger;

import edu.chinasoft.pojo.Goods;

/**
 * 
 * @author cjogng
 * @date 2020年1月19日:下午3:08:40
 * @version V1.0
 * @Description: 查看购物车
*/
@WebServlet(name="myWatchShoppingCartForServlet",value="/servlet/watchshoppingcartforservlet")
public class  WatchShoppingCartForServlet  extends HttpServlet {
	private static Logger logger = Logger.getLogger( WatchShoppingCartForServlet .class);
	
	/**
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" WatchShoppingCartForServlet >doGet start.......");
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		HttpSession session = request.getSession(false);
		List<Goods> goodsList=null;
		if(session!=null) {
			goodsList = (List<Goods>)session.getAttribute("shop");
		}
		
		
		if(goodsList==null) {    //没有商品添加到购物车
			out.write("没有商品添加到购物车！");
		}else {      //购物车里有内容
			out.write("购物车里的商品为：<br>");
			for(Goods element:goodsList) {
				out.write(element.getId()+":"+element.getGoodsName()+"<br>");
			}
			
		}
		
		
		
		
		
		logger.debug(" WatchShoppingCartForServlet >doGet end.......");
	}
	
	/**
	 * 
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		logger.debug(" WatchShoppingCartForServlet >doPost start.......");
		this.doGet(request, response);
		
		logger.debug(" WatchShoppingCartForServlet >doPost end.......");
	}
	
}